ADdata2 <- read.csv("D:/1大学生活/大三下/zxy/R语言/ADdata/ADdata2.csv", header = TRUE, row.names = 1, stringsAsFactors = FALSE)

# 保留行名
row_names_ad <- rownames(ADdata2)
# 尝试将所有列强制转换为数值型 (非数值会变成NA)
ADdata2_numeric <- as.data.frame(lapply(ADdata2, function(col) suppressWarnings(as.numeric(as.character(col)))))
# 恢复行名
rownames(ADdata2_numeric) <- row_names_ad


#层次聚类分析
# 计算样本间距离 (转置后计算行距离)
dist_matrix <- dist(t(ADdata2_numeric))

# 执行层次聚类 (默认 complete linkage)
hclust_result <- hclust(dist_matrix, method = "complete")

#绘制树状图
plot(hclust_result,
     main = "ADdata_cluster", # 图标题
     xlab = "Samples",        # X轴标签
     ylab = "Height",         # Y轴标签
     sub = NULL,                   # 副标题
     hang = -1,                    # 标签底部对齐
     cex = 0.8)                    # 标签字体大小 (可调整)
